package starcoast.bocai.com.starcoast.activitys.work;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import starcoast.bocai.com.starcoast.R;
import starcoast.bocai.com.starcoast.adapter.SetttleGridAdapter;
import starcoast.bocai.com.starcoast.adapter.SetttleListAdapter;
import starcoast.bocai.com.starcoast.common.BaseActivity;
import starcoast.bocai.com.starcoast.view.ExpandTabView;
import starcoast.bocai.com.starcoast.view.MyGridView;
import starcoast.bocai.com.starcoast.view.MyListView;
import starcoast.bocai.com.starcoast.view.ViewRight;

/**
 * Created by admin on 2016/6/16.
 */
public class SettledEnterpriseActivity extends BaseActivity {
    private ExpandTabView expandTabView;
    private ArrayList<View> mViewArray = new ArrayList<View>();
    private ViewRight viewRight;
    @Bind(R.id.settle_grid)
    MyGridView settle_grid;
    @Bind(R.id.lv_settle)
    MyListView lv_settle;
    SetttleListAdapter listAdapter;
    SetttleGridAdapter gridAdapter;
    private String[] items = new String[] { "第一个", "第二个", "第三个", "第四个"};//显示字段
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settle_enterprise);
        ButterKnife.bind(this);
        initView();
        initVaule();
        initListener();
    }
    private void initView() {
        listAdapter = new SetttleListAdapter(this);
        gridAdapter = new SetttleGridAdapter(this);
        settle_grid.setAdapter(gridAdapter);
        lv_settle.setAdapter(listAdapter);
        expandTabView = (ExpandTabView) findViewById(R.id.expandtab_view);
        viewRight = new ViewRight(this,items);
        initToolbar("入驻企业");
        initToolBack();
    }
    private void initVaule() {
        mViewArray.add(viewRight);
        ArrayList<String> mTextArray = new ArrayList<String>();
        mTextArray.add("全部");
        expandTabView.setValue(mTextArray, mViewArray);

    }

    private void initListener() {
        viewRight.setOnSelectListener(new ViewRight.OnSelectListener() {
            @Override
            public void getValue(String distance, String showText) {
                onRefresh(viewRight, showText);
            }
        });
    }
    private void onRefresh(View view, String showText) {
        expandTabView.onPressBack();
        int position = getPositon(view);
        if (position >= 0 && !expandTabView.getTitle(position).equals(showText)) {

        }
        Toast.makeText(SettledEnterpriseActivity.this, showText, Toast.LENGTH_SHORT).show();
    }
    private int getPositon(View tView) {
        for (int i = 0; i < mViewArray.size(); i++) {
            if (mViewArray.get(i) == tView) {
                return i;
            }
        }
        return -1;
    }
    @Override
    public void onBackPressed() {

        if (!expandTabView.onPressBack()) {
            finish();
        }

    }
}
